package com.ruoyi.web.controller.dgw;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dgw.domain.Fodder;
import com.ruoyi.dgw.service.IFodderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 饲料Controller
 * 
 * @author ll
 * @date 2022-01-07
 */
@RestController
@RequestMapping("/dgw/fodder")
public class FodderController extends BaseController
{
    @Autowired
    private IFodderService fodderService;

    /**
     * 查询饲料列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:fodder:list')")
    @GetMapping("/list")
    public TableDataInfo list(Fodder fodder)
    {
        startPage();
        List<Fodder> list = fodderService.selectFodderList(fodder);
        return getDataTable(list);
    }

    /**
     * 导出饲料列表
     */
    @PreAuthorize("@ss.hasPermi('dgw:fodder:export')")
    @Log(title = "饲料", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Fodder fodder)
    {
        List<Fodder> list = fodderService.selectFodderList(fodder);
        ExcelUtil<Fodder> util = new ExcelUtil<Fodder>(Fodder.class);
        return util.exportExcel(list, "饲料数据");
    }

    /**
     * 获取饲料详细信息
     */
    @PreAuthorize("@ss.hasPermi('dgw:fodder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fodderService.selectFodderById(id));
    }

    /**
     * 新增饲料
     */
    @PreAuthorize("@ss.hasPermi('dgw:fodder:add')")
    @Log(title = "饲料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Fodder fodder)
    {
        return toAjax(fodderService.insertFodder(fodder));
    }

    /**
     * 修改饲料
     */
    @PreAuthorize("@ss.hasPermi('dgw:fodder:edit')")
    @Log(title = "饲料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Fodder fodder)
    {
        return toAjax(fodderService.updateFodder(fodder));
    }

    /**
     * 删除饲料
     */
    @PreAuthorize("@ss.hasPermi('dgw:fodder:remove')")
    @Log(title = "饲料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fodderService.deleteFodderByIds(ids));
    }
}
